/**
 * Header file for messages.
 * @author Paweł Pawłowski <abdul-pablo@tlen.pl>
 * @author Leily Zafari
 */


#ifndef MESSAGES_H
#define MESSAGES_H

#include "watering.h"

//bit pattern for renew/requested_data fields of messages
#define WATER_LEVEL_DATA_SIG 1
#define HUMIDITY_LEVEL_DATA_SIG 2
#define VALVE_STATE_DATA_SIG 4

//nodes ids of motes
enum NodesIds {
	TankNodeId = 32,
	ValveNodeId = 26,
	GatewayNodeId = 25,
	SoilNodeId = 30
};

//messages definitions
typedef nx_struct HumidityMsg
{
	nx_uint32_t humidity; //no nx_double_t data type -> no support for platform independent float/double numbers
} HumidityMsg;

typedef nx_struct WaterLevelMsg
{
	nx_uint32_t water;
} WaterLevelMsg;

typedef nx_struct ValveStateMsg
{
	nx_uint8_t valve;
} ValveStateMsg;

typedef nx_struct SystemStateMsgToGateway
{
	nx_uint32_t humidity;
	nx_uint32_t water;
	nx_uint8_t valve;
} SystemStateMsgToGateway;

typedef nx_struct DataRequestMsgToGateway
{
	nx_uint8_t requested_data; //bitwise
	nx_uint8_t renew; //bitwise
} DataRequestMsgToGateway;

typedef nx_struct SystemStateMsgToUSB
{
	nx_uint32_t humidity;
	nx_uint32_t water;
	nx_uint8_t valve;
} SystemStateMsgToUSB;

typedef nx_struct DataRequestMsgToSink
{
	nx_uint8_t requested_data; //bitwise
	nx_uint8_t renew; //bitwise
} DataRequestMsgToSink;

typedef nx_struct DataRequestMsgToSensorNode
{
	nx_uint8_t renew;
} DataRequestMsgToSensorNode;

typedef nx_struct NoResponseMsg
{
	nx_uint8_t absent_node_id;
} NoResponseMsg;

typedef nx_struct ValveControlMsgToValve
{
	nx_uint8_t valve;
} ValveControlMsgToValve;

typedef nx_struct ValveControlMsgToGateway
{
	nx_uint8_t valve;
} ValveControlMsgToGateway;

typedef nx_struct SystemAlertMsgToGateway {
	nx_uint8_t alert;
} SystemAlertMsgToGateway;

typedef nx_struct SystemAlertMsgToUSB {
	nx_uint8_t alert;
} SystemAlertMsgToUSB;

//possible system alerts definition
enum {
	NO_ALERT = 1,
	WATER_BELOW_MIN = 2,
	WATER_BELOW_WARN = 3,
	SOIL_DRY_AND_WATER_BELOW_MIN = 4
};


//AM types for different messages
enum {
	AM_DATAREQUESTMSGTOGATEWAY = 0x11,
	AM_VALVECONTROLMSGTOGATEWAY = 0x10,
	AM_SYSTEMSTATEMSGTOUSB = 0x12,
	AM_SYSTEMALERTMSGTOUSB = 0x14,

	AM_VALVECONTROLMSGTOVALVE = 0x20,
	AM_DATAREQUESTMSGTOSINK = 0x21,
	AM_VALVESTATEMSG = 0x22,
	AM_HUMIDITYMSG = 0x23,
	AM_WATERLEVELMSG = 0x24,
	AM_SYSTEMSTATEMSGTOGATEWAY = 0x25,
	AM_DATAREQUESTMSGTOSENSORNODE = 0x26,
	AM_NORESPONSEMSG = 0x27,
	AM_SYSTEMALERTMSGTOGATEWAY = 0x28
};

#endif /* MESSAGES_H */
